(function(){
  nsbase.views.friendDetail = new FriendDetailFunc();

  function FriendDetailFunc () {
    var _self = this;

    _self.init = init;

    var socialActions = nsbase.config.actionUrl.social,
        utilities = nsbase.utility,
        clientResource = nsbase.resources.clientResource;

    var _friendId = utilities.trim($("#txtFriendId").val());
    var cssClass={
      selected:"selected"
    };
    
    function init () {
      $(".nav_menu li.Social").addClass(cssClass.selected);

      $("#btnAddFriend").click(function () {
          var sender = $(this);
          var $container = sender.parent(".operate_btn:first");
          $container.mask();
          var param = {
            friendId: _friendId
          }
          nsbase.ajax.request(socialActions.addFriend,param,function(result){
            $container.unmask();
            if(result.success){
                utilities.errorDialog(clientResource.msgWaitForConfirm);
            }
          },function () {
            $container.unmask();
          });
      });

      $("#btnDelFriend").click(function () {
          var sender = $(this);
          if(!confirm(clientResource.msgDelFriendConfirm)){
            return;
          }
          var $container = sender.parent(".operate_btn:first");
          $container.mask();
          var param = {
            friendId: _friendId
          }
          nsbase.ajax.request(socialActions.delFriend,param,function(result){
            $container.unmask();
            if(result.success){
                location.reload();
            }
          },function () {
            $container.unmask();
          });
      });
    }
  }
})();
